GetCustomersQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 23
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 16 2
1
import { Inject } from '@nestjs/common';
2
import { QueryHandler } from '@nestjs/cqrs';
3
import { GetCustomersQuery } from './GetCustomersQuery';
4
import { CustomerView } from '../View/CustomerView';
5
import { ICustomerRepository } from 'src/Domain/Customer/Repository/ICustomerRepository';
6
import { Pagination } from 'src/Application/Common/Pagination';
7
8
@QueryHandler(GetCustomersQuery)
9
export class GetCustomersQueryHandler {
10
  constructor(
11
    @Inject('ICustomerRepository')
12
    private readonly customerRepository: ICustomerRepository
13
  ) {}
14
15
  public async execute(
16
    query: GetCustomersQuery
17
  ): Promise<Pagination<CustomerView>> {
18
    const customerViews: CustomerView[] = [];
19
    const [customers, total] = await this.customerRepository.findCustomers(
20
      query.page
21
    );
22
23
    for (const customer of customers) {
24
      customerViews.push(
25
        new CustomerView(customer.getId(), customer.getName())
26
      );
27
    }
28
29
    return new Pagination<CustomerView>(customerViews, total);
30
  }
31
}
32